
jQuery(document).ready(function() {
	
    /*
        Fullscreen background
    */
    $.backstretch([
                    "assets/img/backgrounds/2.jpg"
	              , "assets/img/backgrounds/3.jpg"
	              , "assets/img/backgrounds/1.jpg"
	             ], {duration: 3000, fade: 750});
    
    /*
        Form validation
    */
    $('.login-form input[type="text"], .login-form input[type="password"], .login-form textarea').on('focus', function() {
    	$(this).removeClass('input-error');
    });
    
    $('.login-form').on('click',"#submit", function(e) {
    	
    	$(this).find('input[type="text"], input[type="password"], textarea').each(function(){
    		if( $(this).val() == "" ) {
    			e.preventDefault();
    			$(this).addClass('input-error');
    		}
    		else {
    			$(this).removeClass('input-error');
    		}
    	});

	var login;
		$.ajax({
		  "url": "https://d.apicloud.com/mcm/api/user/login",
		  "cache": false,
		  "headers": {
			"X-APICloud-AppId": "A6938906133488",
			"X-APICloud-AppKey": "30ea6d4fbe548035e18d4a37dc77b68098dd9671.1483600903587"
		  },
		  "data": {
			"username": $("#form-username").val(),//"qwerty",
			"password": $("#form-password").val()//"qwertyqwerty"
		  },
		  "type": "POST"
		}).success(function (data, status, header) {
				  console.log(data)
				   login=data.id
		}).fail(function (header, status, errorThrown) {
		  //fail body
		}).done(function()
		{ 

			$.ajax({
			  "url": "https://d.apicloud.com/mcm/api/hello?filter=%7B%22where%22%3A%7B%7D%2C%22skip%22%3A0%2C%22limit%22%3A20%7D",
			  "cache": false,
			  "headers": {
				"X-APICloud-AppId": "A6938906133488",
				"X-APICloud-AppKey": "30ea6d4fbe548035e18d4a37dc77b68098dd9671.1483600903587",
				"authorization":login
			  },
			  "type": "GET"
			}).success(function (data, status, header) {
			console.log(data)
			}).fail(function (header, status, errorThrown) {
			  //fail body
			})
		});

    });
    
    
});
